package com.apps.ftapp.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.apps.ftapp.R;
import com.apps.ftapp.adapter.MyLessonCacheDetailAdapter;
import com.apps.ftapp.db.LessonChild;
import com.apps.ftapp.util.ActivitySkipUtil;
import com.apps.ftapp.util.L;
import com.apps.ftapp.util.Tools;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 缓存详情
 */
public class MyLessonCacheDetailActivity extends BaseActivity {

    @BindView(R.id.listView)
    ListView listView;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;

    private List<LessonChild> dataList = new ArrayList();
    private MyLessonCacheDetailAdapter myLessonCacheDetailAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_lesson_cache_detail);
        ButterKnife.bind(this);

        //新页面接收数据
        Bundle bundle = this.getIntent().getExtras();
        //接收name值
        String id = bundle.getString("id");

        initView();
        setTitle("缓存课程");
        loadData(id);

    }


    private void loadData(String id) {

        dataList = DataSupport.where("lessonid = ?", id + "").find(LessonChild.class);
        if (null != dataList && dataList.size() > 0) {
            myLessonCacheDetailAdapter.addRes(dataList);
        }

    }

    private void initView() {

        myLessonCacheDetailAdapter = new MyLessonCacheDetailAdapter(getApplicationContext(), dataList);
        listView.setAdapter(myLessonCacheDetailAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


                L.i("main", "::::" + Tools.isNull(dataList.get(position).getFilePath()));
                L.i("main", "::roomId::" + Tools.isNull(dataList.get(position).getRoomId()));

                HashMap map = new HashMap();
                map.put("id", Tools.isNull(dataList.get(position).getChildId()));
                map.put("filePath", Tools.isNull(dataList.get(position).getFilePath()));
                map.put("roomId", Tools.isNull(dataList.get(position).getRoomId()));
                map.put("title", Tools.isNull(dataList.get(position).getTitle()));
                L.i("main", "::::" + map.toString());
                ActivitySkipUtil.skipAnotherActivity(MyLessonCacheDetailActivity.this, CustomizedOffinePlayBackActivity.class, map);


            }
        });
    }


}
